﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BLL;
using DAL;

namespace WebUI.Pages
{
    public partial class mgtSLA : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            UserController usrController = new UserController();
            int idUsuario = usrController.GetUserID(User.Identity.Name);
            int idTeam = usrController.GetUserTeamID(idUsuario);

            if (idTeam != 9)
            {
                Response.Redirect("../Pages/403.aspx");
            }

            if (!Page.IsPostBack)
            {
                SlaController slaController = new SlaController();
                rpSLA.DataSource = slaController.GetSLAs();
                rpSLA.DataBind();
            }
        }



        protected void cmdSalvar_Click(object sender, EventArgs e)
        {
            try
            {
                SlaController slaController = new SlaController();

                string SLA = txtSLA.Text;
                string Prioridade = txtPrioridade.Text;
                int TempoResposta = Convert.ToInt32(txtTempoResposta.Text);
                int TempoSolucao = Convert.ToInt32(txtTempoSolucao.Text);

                slaController.newSLA(SLA, Prioridade, TempoResposta, TempoSolucao);
            }
            catch (Exception ex)
            {
                lblMsg2.Text = "Erro ao cadastrar o Novo SLA. " + ex.Data;
            }
            finally
            {
                txtTempoSolucao.Text = "";
                txtTempoResposta.Text = "";
                txtSLA.Text = "";
                txtPrioridade.Text = "";
                Response.Redirect("../Pages/mgrSLA.aspx");
            }
        }

        protected void rpSLA_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            Response.Redirect("../Pages/editSLA.aspx?id=" + e.CommandArgument.ToString());
        }
    }
}